# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================

load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("//:esbuild.bzl", "esbuild")

package(default_visibility = ["//visibility:public"])

ts_project(
    name = "tfjs-backend-cpu_lib",
    srcs = glob(["src/**/*.ts"]),
    declaration = True,
    extends = "//:tsconfig.json",
    incremental = True,
    out_dir = "dist",
    root_dir = "src",
    source_map = True,
    tsconfig = "tsconfig.json",
    deps = [
        "//tfjs-core",
        "@npm//@types/jasmine",
        "@npm//jasmine",
    ],
)

esbuild(
    name = "tf-backend-cpu.min",
    args = [
        "--resolve-extensions=.mjs,.js",
    ],
    entry_point = "dist/index.js",
    external = [
        "node-fetch",
        "util",
    ],
    minify = True,
    sources_content = True,
    deps = [
        ":tfjs-backend-cpu_lib",
    ],
)

esbuild(
    name = "tf-backend-cpu.node",
    args = [
        "--resolve-extensions=.mjs,.js",
    ],
    entry_point = "dist/index.js",
    external = [
        "node-fetch",
        "util",
    ],
    sources_content = True,
    deps = [
        ":tfjs-backend-cpu_lib",
    ],
)

js_library(
    name = "tfjs-backend-cpu",
    package_name = "@tensorflow/tfjs-backend-cpu",
    srcs = [
        "package.json",
    ],
    deps = [
        ":tf-backend-cpu.min",
        ":tf-backend-cpu.node",
        ":tfjs-backend-cpu_lib",
    ],
)
